
package client.dm;

import java.awt.*;
import java.util.Vector;

public class objTablero extends Canvas {
    
    protected objPaintInstruction currentInstruction = null;
    protected Vector vecPaintInstructions = new Vector();
    
    public void chessBoard() {
    }
    
    public void update(Graphics g) {
        rpaint(g);
    }
    
    public void rpaint(Graphics g) {
        if (vecPaintInstructions.size() == 0) {
            g.setColor(Color.ORANGE); //Estable los colores al tablero
            g.fillRect(0,0,1000,500);//Borde norte
            g.setColor(Color.RED); //Estable los colores al tablero
            g.fillRect(0,500,1000,500);//Sur
            
            currentInstruction = new objPaintInstruction(0,0,5);
            vecPaintInstructions.addElement(currentInstruction);
            
        }
        
        g.setColor(Color.GRAY);
        g.fillRect(0,500,1000,30);
        /*
        for (int i = 0; i < vecPaintInstructions.size(); i++) {
            
            currentInstruction = (objPaintInstruction)vecPaintInstructions.elementAt(i);
            int startRow = currentInstruction.getStartRow();
            int startColumn = currentInstruction.getStartColumn();
            int rowCells = currentInstruction.getRowCells();
            int columnCells = currentInstruction.getColumnCells();
            
            for (int row = startRow; row < (startRow + rowCells); row++) {
                
                for (int column = startColumn; column < (startColumn + columnCells); column++) {
                    drawTile(row, column, g);
                }
                
            }
            
        }
        */
        drawExtra(g);
        
    }
    
    private void drawTile(int row, int column, Graphics g) {
        
        if ((row + 1) % 2 == 0) {
            
            if ((column + 1) % 2 == 0) {
                g.setColor(new Color(255,255,255));
            } else {
                g.setColor(new Color(0,0,0));
            }
            
        } else {
            
            if ((column + 1) % 2 == 0) {
                g.setColor(new Color(0,0,0));
            } else {
                g.setColor(new Color(255,255,255));
            }
            
        }
        
        g.fillRect((50 + (column * 50)), (50 + (row * 50)), 50, 50);
        
    }
    
    protected void drawExtra(Graphics g) {
    }
    
    protected int encontrarFichaX(int coor) {
        
        for (int i = 0; i < 6; i++) {
            System.out.println("XXXX i: "+i+" coor: "+coor+" n1: "+(0 + (i * 100))+" n2: "+(50 + (i * 120)));
            
            if ((coor >= (0 + (i * 100))) && (coor <= (45 + (i * 120)))) {
                return i;
            }
        }
        return 0;
    }
    
    protected int encontrarFichaY(int coor) {
        
        for (int i = 0; i < 14; i++) {
            System.out.println("YYY i: "+i+" coor: "+coor+" n1: "+(0 + (i * 50))+" n2: "+(75 + (i * 50)));
            if ((coor >= (0 + (i * 50))) && (coor <= (80 + (i * 50)))) {
                return i;
            }
        }
        return 0;
    }
    
}